package com.ruoyi.basedata.service.impl;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.basedata.domain.TerminalsFreezeXbWcView;
import com.ruoyi.basedata.mapper.TerminalsFreezeXbWcViewMapper;
import com.ruoyi.basedata.service.ITerminalsFreezeXbWcViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 小表未抄回数据视图Service业务层处理
 *
 * @author gdqt
 * @date 2024-04-03
 */
@Service
public class TerminalsFreezeXbWcViewServiceImpl implements ITerminalsFreezeXbWcViewService {
    @Autowired
    private TerminalsFreezeXbWcViewMapper terminalsFreezeXbWcViewMapper;

    /**
     * 查询小表未抄回数据视图
     *
     * @param tenantId 小表未抄回数据视图主键
     * @return 小表未抄回数据视图
     */
    @Override
    public TerminalsFreezeXbWcView selectTerminalsFreezeXbWcViewByTenantId(String tenantId) {
        return terminalsFreezeXbWcViewMapper.selectTerminalsFreezeXbWcViewByTenantId(tenantId);
    }

    /**
     * 查询小表未抄回数据视图列表
     *
     * @param terminalsFreezeXbWcView 小表未抄回数据视图
     * @return 小表未抄回数据视图
     */
    @Override
    public List<TerminalsFreezeXbWcView> selectTerminalsFreezeXbWcViewList(TerminalsFreezeXbWcView terminalsFreezeXbWcView) {
        return terminalsFreezeXbWcViewMapper.selectTerminalsFreezeXbWcViewList(terminalsFreezeXbWcView);
    }

    /**
     * 新增小表未抄回数据视图
     *
     * @param terminalsFreezeXbWcView 小表未抄回数据视图
     * @return 结果
     */
    @Override
    public int insertTerminalsFreezeXbWcView(TerminalsFreezeXbWcView terminalsFreezeXbWcView) {
        return terminalsFreezeXbWcViewMapper.insertTerminalsFreezeXbWcView(terminalsFreezeXbWcView);
    }

    /**
     * 修改小表未抄回数据视图
     *
     * @param terminalsFreezeXbWcView 小表未抄回数据视图
     * @return 结果
     */
    @Override
    public int updateTerminalsFreezeXbWcView(TerminalsFreezeXbWcView terminalsFreezeXbWcView) {
        return terminalsFreezeXbWcViewMapper.updateTerminalsFreezeXbWcView(terminalsFreezeXbWcView);
    }

    /**
     * 批量删除小表未抄回数据视图
     *
     * @param tenantIds 需要删除的小表未抄回数据视图主键
     * @return 结果
     */
    @Override
    public int deleteTerminalsFreezeXbWcViewByTenantIds(String[] tenantIds) {
        return terminalsFreezeXbWcViewMapper.deleteTerminalsFreezeXbWcViewByTenantIds(tenantIds);
    }

    /**
     * 删除小表未抄回数据视图信息
     *
     * @param tenantId 小表未抄回数据视图主键
     * @return 结果
     */
    @Override
    public int deleteTerminalsFreezeXbWcViewByTenantId(String tenantId) {
        return terminalsFreezeXbWcViewMapper.deleteTerminalsFreezeXbWcViewByTenantId(tenantId);
    }

    @Override
    public List<TerminalsFreezeXbWcView> listMissingTerminalsFreezeXb(TerminalsFreezeXbWcView terminalsFreezeXbWcView) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        Integer dateSpan = terminalsFreezeXbWcView.getDateSpan();
        String dateStart = LocalDate.now().minusDays(dateSpan).toString();
        String dateEnd = LocalDate.now().minusDays(1L).toString();
        paramMap.put("dateStart", dateStart);
        paramMap.put("dateEnd", dateEnd);
        String sheetsCode = terminalsFreezeXbWcView.getSheetsCode();
        if (StrUtil.isNotEmpty(sheetsCode)) {
            paramMap.put("hasSheetCode", "true");
            paramMap.put("sheetCodeList", Arrays.asList(sheetsCode.split(",")));
        }
        return terminalsFreezeXbWcViewMapper.listMissingTerminalsFreezeXb(paramMap);
    }
}
